package com.ftg.learn.chapter09.collection;

import com.ftg.learn.chapter04.Dog;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * set学习
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/8/15 上午8:50
 */
public class LearnSet {

    public static void main(String[] args) {
        Set<Integer> set = new HashSet<>(5);
        System.out.println(set.size());
        set.add(23);
        System.out.println(set.size());
        set.add(23);
        System.out.println(set.size());
        set.add(23);

        System.out.println(set);

        Set<Double> set1 = new HashSet<>(3);
        set1.add(Double.valueOf(3));
        set1.add(3.0);
        set1.add(3.00);

        System.out.println(set1);

        Set<Dog> set3 = new HashSet<>(2);



        // 判断两个对象是否同  equals    hashcode()
        Dog d1 = new Dog();
        d1.setName("abc");
        Dog d3 = new Dog();
        d3.setName("def");
        set3.add(d1);
        set3.add(d3);
        System.out.println("1==>"+d1.hashCode());
        System.out.println("2==>"+d3.hashCode());
        System.out.println(d1.equals(d3)+"===>3");

        System.out.println(set3);

        List<Dog> list1 = new ArrayList<>();
        Dog d2 = new Dog();
        list1.add(d2);
        list1.add(d2);
        System.out.println(list1);

        System.out.println("ab".hashCode());
        System.out.println("b".hashCode());

    }

}
